package com.aizhixin.lab.task.controller;

import java.io.*;
import java.net.URLEncoder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.aizhixin.lab.config.Config;
import com.aizhixin.lab.task.core.ExerciseType;
import com.aizhixin.lab.task.core.TaskInforCode;
import com.aizhixin.lab.task.domain.*;
import com.aizhixin.lab.task.entity.ReleaseTask;
import com.aizhixin.lab.task.entity.ReleaseTaskQuestion;
import com.aizhixin.lab.task.entity.TaskStuAnswer;
import com.aizhixin.lab.task.service.ReleaseTaskQuestionsService;
import com.aizhixin.lab.task.service.ReleaseTaskService;
import io.swagger.annotations.ApiModelProperty;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.aizhixin.lab.account.dto.AccountDTO;
import com.aizhixin.lab.account.service.AccountService;
import com.aizhixin.lab.common.core.ApiReturnConstants;
import com.aizhixin.lab.common.utils.TokenUtil;
import com.aizhixin.lab.task.entity.TaskStuInfor;
import com.aizhixin.lab.task.service.TaskStuAnswerService;
import com.aizhixin.lab.task.service.TaskStuInforService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import javax.servlet.http.HttpServletResponse;


@RestController
@RequestMapping("/api/v1/task/student")
@Api(value = "学生端作业api", tags = "作业列表、查询作业、提交作业")
public class StudentTaskController {
    @Autowired
    private AccountService accountService;
    @Autowired
    private TaskStuInforService taskStuInforService;
    @Autowired
    private TaskStuAnswerService taskStuAnswerService;
    @Autowired
    private ReleaseTaskService releaseTaskService;
    @Autowired
    private ReleaseTaskQuestionsService releaseTaskQuestionsService;
    @Autowired
    private Config config;

    /**
     * 学生作业列表
     *
     * @param token
     * @param
     * @param
     * @param
     * @param
     * @param
     * @return
     */
    @RequestMapping(value = "/getList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "学生任务列表", httpMethod = "POST", notes = "学生任务列表<br><br><b>zhengning</b>")
    public ResponseEntity<?> getList(@RequestHeader("Authorization") String token,
                                     @ApiParam(value = "选填:courseId:课程id;taskStatus:任务状态;uncommit:未提交,pending:待审批,approved:已审批,为空时查询全部", required = false) @RequestBody QueryTaskDomain domain) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }

        result = taskStuInforService.findTaskPage(domain);

        return new ResponseEntity<Map<String, Object>>(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/getStuTaskList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "学生个人任务列表", httpMethod = "POST", notes = "学生任务列表<br><br><b>lwq</b>")
    public ResponseEntity<?> getStuTaskList(@RequestHeader("Authorization") String token,
                                            @ApiParam(value = "选填:courseId:课程id;taskStatus:任务状态;uncommit:未提交,pending:待审批,approved:已审批,为空时查询全部", required = false) @RequestBody QueryTaskDomain domain) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }

        result = taskStuInforService.findTasksPage(domain, account.getId());
        List<StuTaskDomain> o = (List<StuTaskDomain>) result.get(ApiReturnConstants.DATA);
        if (o != null) {
            List<StuTaskDomain> taskStatus = taskStuInforService.getTaskStatus(o);
            result.put(ApiReturnConstants.DATA, taskStatus);
        }
        return new ResponseEntity<Map<String, Object>>(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/studentJoinTask", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "学生参与任务", httpMethod = "GET", notes = "学生任务列表<br><br><b>lwq</b>")
    public ResponseEntity<?> getStuTaskLi(@RequestHeader("Authorization") String token,
                                          @ApiParam(value = "学生任务信息Id", required = true) @RequestParam String taskStuInforId) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(taskStuInforId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "学生任务信息Id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        StuTaskDetailsDomain stuTask = taskStuInforService.getStuTask(taskStuInforId);
        return new ResponseEntity(stuTask, HttpStatus.OK);
    }

    @RequestMapping(value = "/getUnCommitNum", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取学生未完成的数量", httpMethod = "GET", notes = "获取学生未完成的数量<br><br><b>lwq</b>")
    public ResponseEntity<?> getUnCommitNum(@RequestHeader("Authorization") String token) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        Integer commitNum = taskStuInforService.countUnCommitNum(account.getId());
        return new ResponseEntity(commitNum, HttpStatus.OK);
    }
//    @RequestMapping(value = "/saveAnswer", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
//    @ApiOperation(value = "学生做任务(做单个任务)", httpMethod = "POST", notes = "学生做任务(做单个任务)<br><br><b>lwq</b>")
//    public ResponseEntity<?> saveAnswer(@RequestHeader("Authorization") String token,
//                                     @ApiParam(value = "选填:courseId:课程id;taskStatus:任务状态;uncommit:未提交,pending:待审批,approved:已审批,为空时查询全部", required = false) @RequestBody QueryTaskDomain domain) {
//        Map<String, Object> result = new HashMap<String, Object>();
//        AccountDTO account = accountService.getUserByToken(token);
//        if (account == null) {
//            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
//                    HttpStatus.UNAUTHORIZED);
//        }
//
//        result = taskStuInforService.findTaskPage(domain);
//
//        return new ResponseEntity<Map<String, Object>>(result, HttpStatus.OK);
//    }

    @RequestMapping(value = "/getStudentTask", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取该任务下的学生列表", httpMethod = "POST", notes = "学生任务列表<br><br><b>lwq</b>")
    public ResponseEntity<?> getTaskStudentList(@RequestHeader("Authorization") String token,
                                                @ApiParam(value = "ReleaseTaskId:发布任务的ID,taskStatus:任务状态;uncommit:未提交,pending:待审批,approved:已审批,为空时查询全部", required = false) @RequestBody TaskInforDoMain domain) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        List<TaskStuInforDomain> taskInforDomain = taskStuInforService.findTaskInforDomain(domain);

        return new ResponseEntity(taskInforDomain, HttpStatus.OK);
    }

    @RequestMapping(value = "/examineAndApproveStudentTask", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "批阅学生成绩", httpMethod = "POST", notes = "批阅学生成绩<br><br><b>lwq</b>")
    public ResponseEntity<?> examineAndApproveStudentTask(@RequestHeader("Authorization") String token,
                                                          @ApiParam(value = "StuTaskInforDomain", required = false) @RequestBody StuTaskInforDomain domain) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        TaskStuInfor byId = taskStuInforService.findById(domain.getId());
        if (byId == null) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "未查询到该任务");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        byId.setResult(domain.getResult());
        byId.setTaskStatus(TaskInforCode.TASK_STATUS_APPROVED);
        byId.setBatchTime(new Date());
        byId.setComment(domain.getComment());
        ReleaseTask releaseTask = releaseTaskService.findById(byId.getReleaseTaskId());
        if (StringUtils.isEmpty(byId.getGrade())) {
            releaseTask.setPendingNum(releaseTask.getPendingNum() - 1);
        }
        byId.setGrade(domain.getGrade());
        TaskStuInfor save = taskStuInforService.save(byId);
        releaseTaskService.save(releaseTask);
        return new ResponseEntity(save, HttpStatus.OK);
    }

    @RequestMapping(value = "/examineStuAnswer", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "批阅单个试题", httpMethod = "POST", notes = "批阅单个试题<br><br><b>lwq</b>")
    public ResponseEntity<?> examineStuAnswer(@RequestHeader("Authorization") String token,
                                              @ApiParam(value = "", required = false) @RequestBody ExamineStuAnswerDomain domain) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }

        result = taskStuAnswerService.examineStuAnswer(domain);
        return new ResponseEntity(result, HttpStatus.OK);
    }
    @RequestMapping(value = "/examineModuleGrade", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "批阅某个模块的分", httpMethod = "POST", notes = "批阅单个试题<br><br><b>lwq</b>")
    public ResponseEntity<?> examineModuleGrade(@RequestHeader("Authorization") String token,
                                              @ApiParam(value = "", required = false) @RequestBody ExamineModuleGradeDomain domain) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }

        result = taskStuAnswerService.examineModuleGrade(domain);
        return new ResponseEntity(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/getwork", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "查看任务题目列表(包含学生提交答案)", httpMethod = "GET", notes = "查看任务题目列表(包含学生提交答案)<br><br><b>zhengning</b>")
    public ResponseEntity<?> getWork(@RequestHeader("Authorization") String token,
                                     @ApiParam(value = "stuTaskId 学生任务id", required = false) @RequestParam(value = "stuTaskId", required = false) String stuTaskId) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }

        if (StringUtils.isEmpty(stuTaskId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "学生任务id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }

        TaskStuInfor taskStuInfor = taskStuInforService.findById(stuTaskId);
        if (null == taskStuInfor) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "未找到对应的学生任务");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        List<TaskStuQusetionsDomain> list = taskStuInforService.findStuTaskQuestionList(taskStuInfor);
        result.put(ApiReturnConstants.SUCCESS, Boolean.TRUE);
        result.put(ApiReturnConstants.DATA, list);
        return new ResponseEntity<Map<String, Object>>(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/getStudentWork", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "查看任务题目列表(包含学生提交答案)并自动批阅填空及选择题", httpMethod = "GET", notes = "查看任务题目列表(包含学生提交答案)<br><br><b>zhengning</b>")
    public ResponseEntity<?> getStudentWork(@RequestHeader("Authorization") String token,
                                            @ApiParam(value = "stuTaskId 学生任务信息id", required = false) @RequestParam(value = "stuTaskId", required = false) String stuTaskId) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }

        if (StringUtils.isEmpty(stuTaskId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "学生任务id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }

        TaskStuInfor taskStuInfor = taskStuInforService.findById(stuTaskId);
        if (null == taskStuInfor) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "未找到对应的学生任务");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        List<TaskStuQusetionsDomain> list = taskStuInforService.findStuTaskQuestionList(taskStuInfor);
        StuTaskQuestionListDomain stuTaskQuestionListDomain = taskStuInforService.autoJudgeAnswer(list, taskStuInfor);
        result.put(ApiReturnConstants.SUCCESS, Boolean.TRUE);
        result.put(ApiReturnConstants.DATA, stuTaskQuestionListDomain);

        return new ResponseEntity<Map<String, Object>>(result, HttpStatus.OK);
    }
//------------------------------------------------------------------------------------------------------------


    @RequestMapping(value = "/getTaskAvg", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取非客观题的平均分", httpMethod = "GET", notes = "获取非客观题的平均分<br><br><b>lwq</b>")
    public ResponseEntity<?> getTaskAvg(@RequestHeader("Authorization") String token,
                                        @ApiParam(value = "stuTaskId 学生任务信息id", required = false) @RequestParam(value = "stuTaskId", required = false) String stuTaskId) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }

        if (StringUtils.isEmpty(stuTaskId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "学生任务id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }

        TaskStuInfor taskStuInfor = taskStuInforService.findById(stuTaskId);
        if (null == taskStuInfor) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "未找到对应的学生任务");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        List<TaskStuQusetionsDomain> list = taskStuInforService.findStuTaskQuestionList(taskStuInfor);
        result = taskStuInforService.taskAvg(list, taskStuInfor);


        return new ResponseEntity<Map<String, Object>>(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/findTaskAccuracy", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "查看任务正确率", httpMethod = "GET", notes = "查看任务正确率<br><br><b>lwq</b>")
    public ResponseEntity<?> findTaskAccuracy(@RequestHeader("Authorization") String token,
                                              @ApiParam(value = "stuTaskId 学生任务信息id", required = false) @RequestParam(value = "stuTaskId", required = false) String stuTaskId) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }

        if (StringUtils.isEmpty(stuTaskId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "学生任务id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }

        TaskStuInfor taskStuInfor = taskStuInforService.findById(stuTaskId);
        if (null == taskStuInfor) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "未找到对应的学生任务");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        Integer taskAccuracy = taskStuAnswerService.findTaskAccuracy(taskStuInfor.getReleaseTaskId(), taskStuInfor.getStuId());
        result.put(ApiReturnConstants.SUCCESS, Boolean.TRUE);
        result.put(ApiReturnConstants.DATA, taskAccuracy);
        return new ResponseEntity<Map<String, Object>>(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/getCompleteTaskNum", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取未完成和完成的任务数量", httpMethod = "GET", notes = "获取未完成和完成的任务数量<br><br><b>hsh</b>")
    public ResponseEntity<?> getCompleteTaskNum(@RequestHeader("Authorization") String token,
                                                @ApiParam(value = "releaseTaskId 任务Id", required = true) @RequestParam(value = "releaseTaskId", required = true) String releaseTaskId) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(releaseTaskId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "发布的任务Id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        TaskNumDoMain taskNum = taskStuInforService.getTaskNum(releaseTaskId);
        return new ResponseEntity<>(taskNum, HttpStatus.OK);
    }

    @RequestMapping(value = "/getTaskRank", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取任务等级分布", httpMethod = "GET", notes = "获取任务等级分布<br><br><b>hsh</b>")
    public ResponseEntity<?> getTaskRank(@RequestHeader("Authorization") String token,
                                         @ApiParam(value = "releaseTaskId 任务Id", required = true) @RequestParam(value = "releaseTaskId", required = true) String releaseTaskId) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(releaseTaskId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "发布的任务Id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        List<RankNumDomain> taskRank = taskStuInforService.getTaskRank(releaseTaskId);
        return new ResponseEntity<>(taskRank, HttpStatus.OK);
    }
    @RequestMapping(value = "/getModuleAvg", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取非客观题模块平均分", httpMethod = "GET", notes = "获取非客观题模块平均分<br><br><b>hsh</b>")
    public ResponseEntity<?> getModuleAvg(@RequestHeader("Authorization") String token,
                                         @ApiParam(value = "stuInfoId", required = true) @RequestParam(value = "stuInfoId", required = true) String stuInfoId) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(stuInfoId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "stuInfoId不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        return new ResponseEntity<>(taskStuAnswerService.getAvg(stuInfoId), HttpStatus.OK);
    }
    @RequestMapping(value = "/getStuTaskAvg", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取任务总平均分", httpMethod = "GET", notes = "获取任务总平均分<br><br><b>hsh</b>")
    public ResponseEntity<?> getStuTaskAvg(@RequestHeader("Authorization") String token,
                                          @ApiParam(value = "stuInfoId", required = true) @RequestParam(value = "stuInfoId", required = true) String stuInfoId) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(stuInfoId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "stuInfoId不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        return new ResponseEntity<>(taskStuAnswerService.getStuTaskAvg(stuInfoId), HttpStatus.OK);
    }

    @RequestMapping(value = "/saveanswers", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "学生做任务", httpMethod = "POST", notes = "保存答案及附件<br><br><b>hsh</b>")
    public ResponseEntity<?> saveAnswers(@RequestHeader("Authorization") String token,
                                         @ApiParam(value = "<b>必填</b><br>stuTaskId:学生任务id<br>releaseTaskId:发布任务id<br>answerList:答案集合<br>commit:true:提交，false:保存(不传默认为false)") @RequestBody StuAnswerSaveDomain domain) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(domain.getTaskStuId())) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "学生任务id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        TaskStuInfor taskStuInfor = taskStuInforService.findById(domain.getTaskStuId());
        if (null == taskStuInfor) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "学生任务不存在");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        if (null != taskStuInfor.getBatchTime()) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "任务已批阅");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }

        if (domain.getAnswerList().isEmpty()) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "学生答案集合为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }

        if (!domain.getAnswerList().isEmpty()) {
            for (StuAnswerParamsDomain item : domain.getAnswerList()) {

                if (item.getQuestionType() == 60) {
                    if (item.getStuAnswerAccessorylist()!=null&&item.getStuAnswerAccessorylist().size()>0){
                        continue;
                    }
                    if (item.getLanguage().equals("java")) {
                        if (!item.getStuAnswer().trim().equals("class Main {\n" +
                                "public static void main(String[] args) {\n" +
                                "}\n" +
                                "}") && !item.getStuAnswer().trim().equals("")) {
                            String code[] = item.getStuAnswer().split("\n");
                            for (int i = 0; i < code.length; i++) {
                                String codeStr = code[i];
                                if (i > 1 && i < code.length - 2 && "".equals(codeStr.trim())) {
                                    result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
                                    result.put(ApiReturnConstants.ERROR, "编程题答案为空或最后一行有回车,请删除回车后重新提交！");
                                    return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
                                }
                            }
                        } else {
                            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
                            result.put(ApiReturnConstants.ERROR, "编程题答案为空！");
                            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
                        }
                    }
                    if (item.getLanguage().equals("c")) {
                        if (!item.getStuAnswer().trim().equals("#include <stdio.h>\n" +
                                "int main () {\n" +
                                "return 0;\n" +
                                "}") && !item.getStuAnswer().trim().equals("")) {
                            String code[] = item.getStuAnswer().split("\n");
                            for (int i = 0; i < code.length; i++) {
                                String codeStr = code[i];
                                if (i > 1 && i < code.length - 1 && "".equals(codeStr.trim())) {
                                    result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
                                    result.put(ApiReturnConstants.ERROR, "编程题答案为空或最后一行有回车,请删除回车后重新提交！");
                                    return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
                                }
                            }
                        } else {
                            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
                            result.put(ApiReturnConstants.ERROR, "编程题答案为空！");
                            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
                        }

                    }
                }
            }
        }
        domain.setReleaseTaskId(taskStuInfor.getReleaseTaskId());
        result= taskStuAnswerService.saveStuAnswer(account, domain);
        return new ResponseEntity<Map<String, Object>>(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/judgeStudentAnswer", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "批阅学生答案", httpMethod = "GET", notes = "批阅学生答案<br><br><b>lwq</b>")
    public ResponseEntity<?> judgeStudentAnswer(@RequestHeader("Authorization") String token,
                                                @ApiParam(value = "taskStuAnsWer 学生答案Id", required = false) @RequestParam(value = "stuTaskId", required = false) String taskStuAnsWerId,
                                                @ApiParam(value = "isCorrect 是否正确", required = false) @RequestParam(value = "isCorrect", required = false) Integer isCorrect) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }

        TaskStuAnswer taskStuAnswer = taskStuAnswerService.judgeStudentAnswer(taskStuAnsWerId, isCorrect);

        return new ResponseEntity<>(taskStuAnswer, HttpStatus.OK);

    }

    @RequestMapping(value = "/findStudentWork", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "学生查看点评及试题", httpMethod = "GET", notes = "学生查看点评及试题<br><br><b>lwq</b>")
    public ResponseEntity<?> findStudentWork(@RequestHeader("Authorization") String token,
                                             @ApiParam(value = "学生任务信息Id", required = false) @RequestParam String taskStuInforId) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(taskStuInforId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "学生任务信息id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        StuTaskDetailsDomain stuTask = taskStuInforService.findStuTask(taskStuInforId);
        return new ResponseEntity<>(stuTask, HttpStatus.OK);

    }


    @RequestMapping(value = "/exportStudentWork", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "学生导出任务", httpMethod = "GET", notes = "学生导出任务<br><br><b>lwq</b>")
    public ResponseEntity<?> exportStudentWork(
            @ApiParam(value = "学生任务信息Id", required = false) @RequestParam(value = "taskInforId", required = false) String taskInforId,
            HttpServletResponse response) throws IOException {
        Map<String, Object> result = new HashMap<String, Object>();
//        AccountDTO account = accountService.getUserByToken(token);
//        if (account == null) {
//            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
//                    HttpStatus.UNAUTHORIZED);
//        }
        if (StringUtils.isEmpty(taskInforId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "学生任务id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        HSSFWorkbook wb = new HSSFWorkbook();
        StuTaskDetailsDomain stuTask = taskStuInforService.findStuTask(taskInforId);
        HSSFSheet sheet = wb.createSheet("任务表");
        HSSFRow row = sheet.createRow(0);
        row.createCell(0).setCellValue("编号");
        row.createCell(1).setCellValue("题干");
        row.createCell(2).setCellValue("解析");
        row.createCell(3).setCellValue("正确答案");
        row.createCell(4).setCellValue("学生答案");
        row.createCell(5).setCellValue("客观题选项");
        int i = 1;
        for (TaskStuQusetionsDomain t : stuTask.getTaskStuQusetionsDomainList()) {
            HSSFRow row1 = sheet.createRow(i);
            row1.createCell(0).setCellValue(i);
            row1.createCell(1).setCellValue(t.getQuestionContent());
            row1.createCell(2).setCellValue(t.getAnalysis());
            row1.createCell(3).setCellValue(t.getAnswer());
            row1.createCell(4).setCellValue(t.getStuAnswer());
            if (t.getQuestionType().equals(ExerciseType.SINGLE.getIntValue()) || t.getQuestionType().equals(ExerciseType.MULTIPLE.getIntValue()) || ExerciseType.JUDGMENT.getIntValue().equals(t.getQuestionType())) {
                for (int j = 0; j < t.getChoicelist().size(); j++) {
                    row1.createCell(j + 5).setCellValue(t.getChoicelist().get(j).getChoiceContent());
                }
            }
            i++;
        }
        FileOutputStream output = new FileOutputStream(config.getBaseDir() + "/" + stuTask.getTaskName() + ".xls");
        wb.write(output);
        output.flush();
        String basePath = config.getBaseDir() + "/" + stuTask.getTaskName() + ".xls";
        File file = new File(basePath);
        // 取得文件名。
//        String filename = stuTask.getTaskName()+"1.xls";

//        // 取得文件的后缀名。
//        String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase();

        // 以流的形式下载文件。
        InputStream fis = new BufferedInputStream(new FileInputStream(basePath));
        byte[] buffer = new byte[fis.available()];
        fis.read(buffer);
        fis.close();
//        file.delete();
        // 清空response
        response.reset();
        // 设置response的Header
        response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(System.currentTimeMillis() + ".xls", "UTF-8"));
        response.addHeader("Content-Length", "" + file.length());
        OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
        response.setContentType("application/octet-stream;charset=utf-8");
        toClient.write(buffer);
        toClient.flush();
        toClient.close();
        return new ResponseEntity<>(stuTask, HttpStatus.OK);

    }
//    @RequestMapping(value = "/DownloadExcel", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
//    @ApiOperation(value = "下载任务", httpMethod = "GET", notes = "下载任务<br><br><b>lwq</b>")
//    public HttpServletResponse download(HttpServletResponse response) {
//        try {
//            // path是指下载的文件的路径。
//            String basePath =config.getBaseDir()+ "/" +"新的任务plus.xls";
//            File file = new File(basePath);
//            // 取得文件名。
//            String filename = file.getName().toString();
//
//            // 取得文件的后缀名。
//            String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase();
//
//            // 以流的形式下载文件。
//            InputStream fis = new BufferedInputStream(new FileInputStream(basePath));
//            byte[] buffer = new byte[fis.available()];
//            fis.read(buffer);
//            fis.close();
//            // 清空response
//            response.reset();
//            // 设置response的Header
//            response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes(),"ISO-8859-1"));
//            response.addHeader("Content-Length", "" + file.length());
//            OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
//            response.setContentType("application/octet-stream");
//            toClient.write(buffer);
//            toClient.flush();
//            toClient.close();
//        } catch (IOException ex) {
//            ex.printStackTrace();
//        }
//        return response;
//    }


    @RequestMapping(value = "/findStuErrorQuestion", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "查看学生做错的题目及答案", httpMethod = "GET", notes = "查看学生做错的题目及答案<br><br><b>lwq</b>")
    public ResponseEntity<?> findStuErrorQuestion(@RequestHeader("Authorization") String token,
                                                  @ApiParam(value = "releaseTaskQuestionId 发布任务问题的Id", required = true) @RequestParam(value = "releaseTaskQuestionId", required = true) String releaseTaskQuestionId,
                                                  @ApiParam(value = "stuId 学生Id", required = true) @RequestParam(value = "stuId", required = true) Long stuId) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(releaseTaskQuestionId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "学生任务问题id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        if (stuId == 0L || stuId == null) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "学生id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        QuestionAndStuAnswerDomain questionAndStuAnswer = releaseTaskService.findQuestionAndStuAnswer(releaseTaskQuestionId, stuId);
        return new ResponseEntity<>(questionAndStuAnswer, HttpStatus.OK);

    }

    @RequestMapping(value = "/findEasyWrongTopic", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "统计易错题", httpMethod = "GET", notes = "统计易错题<br><br><b>lwq</b>")
    public ResponseEntity<?> findEasyWrongTopic(@RequestHeader("Authorization") String token,
                                                @ApiParam(value = "releaseTaskId 任务Id", required = true) @RequestParam(value = "releaseTaskId", required = true) String releaseTaskId) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(releaseTaskId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "发布任务id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }

        List<EasyWrongTopic> easyWrongTopic = releaseTaskService.findEasyWrongTopic(releaseTaskId);
        if (easyWrongTopic.size() <= 0) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.TRUE);
            result.put(ApiReturnConstants.ERROR, "这个任务没有易错题");
        }
        return new ResponseEntity<>(easyWrongTopic, HttpStatus.OK);

    }

    @RequestMapping(value = "/findErrorList", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "查看错题列表", httpMethod = "GET", notes = "查看错题列表<br><br><b>lwq</b>")
    public ResponseEntity<?> findErrorList(@RequestHeader("Authorization") String token,
                                           @ApiParam(value = "releaseTaskId 任务Id", required = true) @RequestParam(value = "releaseTaskId", required = true) String releaseTaskId,
                                           @ApiParam(value = "stuId 任务Id", required = true) @RequestParam Long stuId) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(releaseTaskId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "发布任务id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }

        List<EasyWrongTopic> easyWrongTopic = taskStuInforService.getQuestionErrorList(releaseTaskId, stuId);
        if (easyWrongTopic.size() <= 0) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.TRUE);
            result.put(ApiReturnConstants.ERROR, "这个任务没有错题");
        }
        return new ResponseEntity<>(easyWrongTopic, HttpStatus.OK);

    }

    @RequestMapping(value = "/findTaskStatistics", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "统计任务提交情况", httpMethod = "GET", notes = "统计任务提交情况<br><br><b>lwq</b>")
    public ResponseEntity<?> findTaskStatistics(@RequestHeader("Authorization") String token,
                                                @ApiParam(value = "releaseTaskId 任务Id", required = true) @RequestParam(value = "releaseTaskId", required = true) String releaseTaskId) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(releaseTaskId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "发布任务id不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }

        TaskNumDoMain taskStatistics = taskStuInforService.findTaskStatistics(releaseTaskId);
        if (null != taskStatistics) {
            return new ResponseEntity<>(taskStatistics, HttpStatus.OK);
        } else {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "任务不存在");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
    }

    @RequestMapping(value = "/isShowAnswer", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "是否显示答案(show:显示,hide隐藏)", httpMethod = "GET", notes = "统计任务提交情况<br><br><b>lwq</b>")
    public ResponseEntity<?> isShowAnswer(@RequestHeader("Authorization") String token,
                                          @ApiParam(value = "学生任务信息Id", required = true) @RequestParam(value = "taskStuInforId", required = true) String taskStuInforId,
                                          @ApiParam(value = "是否显示学生答案", required = true) @RequestParam(value = "isShowAnswer", required = true) String isShowAnswer) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(taskStuInforId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "学生任务信息Id");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
//        taskStuInforService.findById()
        int i = taskStuInforService.updateIsShowAnswer(taskStuInforId, isShowAnswer);
        if (i != 0) {
            return new ResponseEntity<>(HttpStatus.OK);
        } else {
            return new ResponseEntity<>("任务信息不存在", HttpStatus.OK);
        }
    }

    @RequestMapping(value = "/isShowGrade", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "是否显示分数(show:显示,hide隐藏)", httpMethod = "GET", notes = "是否显示分数<br><br><b>lwq</b>")
    public ResponseEntity<?> isShowGrade(@RequestHeader("Authorization") String token,
                                         @ApiParam(value = "学生任务信息Id", required = true) @RequestParam(value = "taskStuInforId", required = true) String taskStuInforId,
                                         @ApiParam(value = "是否显示学生分数", required = true) @RequestParam(value = "isShowGrade", required = true) String isShowGrade) {
        Map<String, Object> result = new HashMap<String, Object>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(),
                    HttpStatus.UNAUTHORIZED);
        }
        if (StringUtils.isEmpty(taskStuInforId)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "学生任务信息Id");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }
        if (StringUtils.isEmpty(isShowGrade)) {
            result.put(ApiReturnConstants.SUCCESS, Boolean.FALSE);
            result.put(ApiReturnConstants.ERROR, "修改信息不能为空");
            return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
        }

        int i = taskStuInforService.updateIsShowGrade(taskStuInforId, isShowGrade);
        if (i != 0) {
            return new ResponseEntity<>(HttpStatus.OK);
        } else {
            return new ResponseEntity<>("修改信息不能为空", HttpStatus.OK);
        }
    }


//
//	@RequestMapping(value = "/findsutinfo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
//	@ApiOperation(value = "查询学生信息", httpMethod = "GET", notes = "查询学生信息<br><br><b>likai</b>")
//	public ResponseEntity<Map<String, Object>> findSutInfo(@RequestHeader("Authorization") String token,
//														   @ApiParam(value = "学生作业id（em_work_stu_info）", required = true) @RequestParam(value = "workStuId", required = true) String workStuId) {
//		Map<String, Object> result = new HashMap<String, Object>();
//		AccountDTO dto = authUtilService.getSsoUserInfo(token);
//		if (dto == null || dto.getId() == null) {
//			result.put(ApiReturnConstants.RESULT, Boolean.FALSE);
//			result.put(ApiReturnConstants.CODE, PublicErrorCode.AUTH_EXCEPTION.getIntValue());
//			result.put(ApiReturnConstants.CAUSE, "未授权");
//			return new ResponseEntity<Map<String, Object>>(result, HttpStatus.UNAUTHORIZED);
//		}
//		if (workStuId == null || workStuId.equals("")) {
//			result.put(ApiReturnConstants.RESULT, Boolean.FALSE);
//			result.put(ApiReturnConstants.CAUSE, "学生作业id为空");
//			return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
//		}
//		WorkStuInfoDomain workStuInfo = workStuInfoService.findByIdWorkInfo(workStuId);
//
//		result.put(ApiReturnConstants.RESULT, Boolean.TRUE);
//		result.put(ApiReturnConstants.DATA, workStuInfo);
//		return new ResponseEntity<Map<String, Object>>(result, HttpStatus.OK);
//	}
//
//	@RequestMapping(value = "/getUnCommitHomeWork", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
//	@ApiOperation(value = "查询学生作业未提交数", httpMethod = "GET", notes = "查询学生作业未提交数<br><br><b>xiagen</b>")
//	public ResponseEntity<Map<String, Object>> getUnCommitHomeWork(@RequestHeader("Authorization") String token,
//																   @ApiParam(value = "whetherCommit提交状态（1：已提交，0：未提交）", required = true) @RequestParam(value = "whetherCommit", required = true) Integer whetherCommit,
//																   @ApiParam(value = "所属课程id") @RequestParam(value = "courseId", required = false, defaultValue = "0") Long courseId) {
//		Map<String, Object> result = new HashMap<String, Object>();
//		AccountDTO dto = authUtilService.getSsoUserInfo(token);
//		if (dto == null || dto.getId() == null) {
//			result.put(ApiReturnConstants.RESULT, Boolean.FALSE);
//			result.put(ApiReturnConstants.CODE, PublicErrorCode.AUTH_EXCEPTION.getIntValue());
//			result.put(ApiReturnConstants.CAUSE, "未授权");
//			return new ResponseEntity<Map<String, Object>>(result, HttpStatus.UNAUTHORIZED);
//		}
//		if (whetherCommit == null || whetherCommit.equals("")) {
//			result.put(ApiReturnConstants.RESULT, Boolean.FALSE);
//			result.put(ApiReturnConstants.CAUSE, "提交状态为空");
//			return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
//		}
//		result.put(ApiReturnConstants.RESULT, Boolean.TRUE);
//		result.put(ApiReturnConstants.DATA,
//				workStuInfoService.getCountUncommitHomeWork(dto.getId(), whetherCommit, courseId));
//		return new ResponseEntity<Map<String, Object>>(result, HttpStatus.OK);
//
//	}
//
//
//	@RequestMapping(value = "/findQuestionsId", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
//	@ApiOperation(value = "根据试题id查询答案", httpMethod = "GET", notes = "根据试题id查询答案<br><br><b>xiagen</b>")
//	public ResponseEntity<Map<String, Object>> findQuestionsId(@RequestHeader("Authorization") String token,
//															   @ApiParam(value = "试题的id") @RequestParam(value = "questionsId", required = true) String questionsId) {
//		Map<String, Object> result = new HashMap<String, Object>();
//		AccountDTO dto = authUtilService.getSsoUserInfo(token);
//		if (dto == null || dto.getId() == null) {
//			result.put(ApiReturnConstants.RESULT, Boolean.FALSE);
//			result.put(ApiReturnConstants.CODE, PublicErrorCode.AUTH_EXCEPTION.getIntValue());
//			result.put(ApiReturnConstants.CAUSE, "未授权");
//			return new ResponseEntity<Map<String, Object>>(result, HttpStatus.UNAUTHORIZED);
//		}
//		if (questionsId == null || "".equals(questionsId)) {
//			result.put(ApiReturnConstants.RESULT, Boolean.FALSE);
//			result.put(ApiReturnConstants.CAUSE, "试题id不能为空");
//			return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
//		}
//
//		try {
//			StuAnswerDomain stuAnswerDomain = stuAnswerService.findByQuestionsbIdAndStuId(questionsId, dto.getId());
//			result.put(ApiReturnConstants.RESULT, Boolean.TRUE);
//			result.put(ApiReturnConstants.DATA, stuAnswerDomain);
//		} catch (Exception ex) {
//			ex.printStackTrace();
//			result.put(ApiReturnConstants.RESULT, Boolean.FALSE);
//			result.put(ApiReturnConstants.CAUSE, ex);
//			result.put(ApiReturnConstants.CODE, PublicErrorCode.QUERY_EXCEPTION.getIntValue());
//			return new ResponseEntity<Map<String, Object>>(result, HttpStatus.EXPECTATION_FAILED);
//		}
//		return new ResponseEntity<Map<String, Object>>(result, HttpStatus.OK);
//
//	}

}
